package com.lost.octopus.es.processor.config.es;

import com.lost.octopus.es.processor.config.es.alias.AliasElasticsearchRestTemplate;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

/**
 * 自定义扩展 ElasticsearchRestTemplate 扩展出可以返回自定义别名的 IndexOperations
 * 重写{@link ElasticsearchRestTemplate#indexOps(Class)}
 * @author zhangbh
 * @date 2022/10/31 0031 14:13
 */
@Configuration
@AutoConfigureBefore({AbstractElasticsearchConfiguration.class})
public class CustomElasticSearchConfig {


    @Bean(name = "aliasElasticsearchRestTemplate")
    public ElasticsearchRestTemplate elasticsearchRestTemplate(RestHighLevelClient client) {
        // 自定义扩展 ElasticsearchRestTemplate 扩展出可以返回自定义别名的 IndexOperations
        return new AliasElasticsearchRestTemplate(client);
    }
}
